﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using Microsoft.SharePoint;

namespace ServBus.ListForm2010.Common.XSNOperator
{

    #region Abstract Class Definition

    public abstract class XFieldInfo
    {
        #region Accessor

        public XSNOperator XSNOperator = new XSNOperator();
        public string InternalName { get; protected set; }

        public string DisplayName { get; protected set; }

        public string UniqueName { get; protected set; }

        public FieldInfoType FieldInfoType { get; protected set; }

        public bool ReadOnly { get; protected set; }

        public bool Hidden { get; protected set; }

        public string DefaultValue { get; protected set; }

        #endregion

        #region Field Definition for XSN

        //Myschema.xsd
        public virtual string GetMyschemaElementDef()
        {
            return string.Empty;
        }

        //Manifest.xsf
        public virtual string GetManifestFileDef()
        {
            return string.Empty;
        }

        public virtual string GetManifestDataObjectDef()
        {
            return string.Empty;
        }

        public virtual string GetManifestXmlToEditDef()
        {
            return string.Empty;
        }

        //Sampledata.xml
        public virtual string GetSampledataOptionDSElementDef()
        {
            return string.Empty;
        }

        public virtual string GetSampledataDataObjectDef()
        {
            return string.Empty;
        }

        //Template.xml
        public virtual string GetTemplateElementDef()
        {
            return string.Empty;
        }

        //View.xsl
        public virtual string GetViewElementDef()
        {
            return string.Empty;
        }

        public virtual string GetViewSubElementDef()
        {
            return string.Empty;
        }

        //Choice.xml
        public virtual string GetChoiceXMLElementDef()
        {
            return string.Empty;
        }

        //Choice.xsd
        public virtual string GetChoiceXSDElementDef()
        {
            return string.Empty;
        }

        #endregion
    }

    #endregion

    #region Field Class Definition

    //TextField
    public class TextFieldInfo : XFieldInfo
    {
        public TextFieldInfo(SPFieldText p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Text;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            return
                string.Format(
                    "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" type=\"xsd:string\" nillable=\"true\"  />",
                    UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr style=\"MIN-HEIGHT: 31px\" class=\"xdTableOffsetRow\">"
                         +
                         "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         +
                         "<td class=\"xdTableOffsetCellComponent\" style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span class=\"xdlabel\"></span>"
                         + "<font style=\"BACKGROUND-COLOR: #ffffff\"></font>"
                         +
                         "<span hideFocus=\"1\" class=\"xdTextBox\" title=\"\" tabIndex=\"0\" xd:xctname=\"PlainText\" xd:CtrlId=\"CTRL1\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" style=\"WIDTH: 100%\" >"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\" />"
                         + "</span>"
                         + "</td>"
                         + "</tr>";
            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         +
                         "<span hideFocus=\"1\" class=\"xdTextBox\" tabIndex=\"0\" xd:xctname=\"PlainText\" xd:CtrlId=\"CTRL12\" xd:binding=\"tns:{0}\" style=\"WIDTH: 100%\">"
                         + "<xsl:value-of select=\"tns:{0}\" />"
                         + "</span>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //DateTime,
    public class DateTimeFieldInfo : XFieldInfo
    {
        public DateTimeFieldInfo(SPFieldDateTime p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.DateTime;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");

            DateOnly = p_SPField.DisplayFormat.Equals(SPDateTimeFieldFormatType.DateOnly);
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef =
                   string.Format(
                       "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" type=\"xsd:dateTime\" nillable=\"true\" />",
                       UniqueName, DisplayName);
            if (DateOnly)
            {
                elementDef =
                    string.Format(
                        "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" type=\"xsd:date\" nillable=\"true\" />",
                        UniqueName, DisplayName);
            }
            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def;
            if (DateOnly)
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                      + "<td class=\"xdTableOffsetCellLabel\""
                      + " style=\"PADDING-BOTTOM: 4px; PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<h4>"
                      + "<span class=\"xdlabel\">{1}</span>"
                      + "</h4>"
                      + "</td>"
                      + "<td class=\"xdTableOffsetCellComponent\""
                      +
                      " style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<div style=\"WIDTH: 100%\" class=\"xdDTPicker\" title=\"\" noWrap=\"1\""
                      + " xd:CtrlId=\"{0}_1\" xd:xctname=\"DTPicker\">"
                      + "<span hideFocus=\"1\""
                      + " class=\"xdDTText xdBehavior_FormattingNoBUI\""
                      + " contentEditable=\"true\" tabIndex=\"0\""
                      + " xd:disableEditing=\"no\""
                      + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                      + " xd:xctname=\"DTPicker_DTText\" xd:boundProp=\"xd:num\""
                      + " xd:datafmt=\"&quot;date&quot;,&quot;dateFormat:Short Date;&quot;\""
                      + " xd:innerCtrl=\"_DTText\">"
                      + "<xsl:attribute name=\"xd:num\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;date&quot;,&quot;dateFormat:Short Date;&quot;)\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "<button class=\"xdDTButton\" xd:xctname=\"DTPicker_DTButton\""
                      + " xd:innerCtrl=\"_DTButton\" tabIndex=\"-1\">"
                      + "<img src=\"res://infopath.exe/calendar.gif\"/>"
                      + " </button>"
                      + "</div>"
                      + "</td>"
                      + "</tr>";
            }
            else
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                      + "<td class=\"xdTableOffsetCellLabel\""
                      + " style=\"PADDING-BOTTOM: 4px; PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<h4>"
                      + "<span class=\"xdlabel\">{1}</span>"
                      + "</h4>"
                      + "</td>"
                      + "<td class=\"xdTableOffsetCellComponent\""
                      +
                      " style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      +
                      "<div style=\"WIDTH: 147px\" class=\"xdDTPicker\" title=\"\" noWrap=\"1\" xd:xctname=\"DTPicker\" xd:CtrlId=\"CTRL1\">"
                      +
                      "<span hideFocus=\"1\" class=\"xdDTText xdBehavior_FormattingNoBUI\" contentEditable=\"true\" tabIndex=\"0\" xd:xctname=\"DTPicker_DTText\""
                      + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" xd:datafmt=\"&quot;datetime&quot;,&quot;dateFormat:Short Date;timeFormat:none;&quot;\" xd:boundProp=\"xd:num\" xd:innerCtrl=\"_DTText\" >"
                      + "<xsl:attribute name=\"xd:num\"  >"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose >"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\" >"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;datetime&quot;,&quot;dateFormat:Short Date;timeFormat:none;&quot;)\" />"
                      + "</xsl:when>"
                      + "<xsl:otherwise >"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\" />"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      +
                      "<button class=\"xdDTButton\" xd:xctname=\"DTPicker_DTButton\" xd:innerCtrl=\"_DTButton\" tabIndex=\"0\" >"
                      + "<img src=\"res://infopath.exe/calendar.gif\"/>"
                      + "</button>"
                      + "</div>"
                      +
                      "<span hideFocus=\"1\" class=\"xdTextBox xdBehavior_Formatting\" title=\"\" contentEditable=\"true\" tabIndex=\"0\" xd:xctname=\"PlainText\" xd:CtrlId=\"CTRL1\""
                      + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" xd:datafmt=\"&quot;datetime&quot;,&quot;dateFormat:none;&quot;\" xd:boundProp=\"xd:num\" style=\"WIDTH: 144px\">"
                      + "<xsl:attribute name=\"xd:num\" >"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\" />"
                      + "</xsl:attribute>"
                      + "<xsl:choose >"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\" >"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;datetime&quot;,&quot;dateFormat:none;&quot;)\" />"
                      + "</xsl:when>"
                      + "<xsl:otherwise >"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\" />"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "</td>"
                      + "</tr>";
            }
            def = string.Format(def, UniqueName, DisplayName);
            return def;
        }

        public override string GetViewSubElementDef()
        {
            string def;
            if (DateOnly)
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<div style=\"WIDTH: 100%\" class=\"xdDTPicker\" title=\"\" noWrap=\"1\""
                      + " xd:CtrlId=\"{0}_12\" xd:xctname=\"DTPicker\">"
                      + "<span hideFocus=\"1\""
                      + " class=\"xdDTText xdBehavior_FormattingNoBUI\""
                      + " contentEditable=\"true\" tabIndex=\"0\""
                      + " xd:disableEditing=\"no\""
                      + " xd:binding=\"tns:{0}\""
                      + " xd:xctname=\"DTPicker_DTText\" xd:boundProp=\"xd:num\""
                      + " xd:datafmt=\"&quot;date&quot;,&quot;dateFormat:Short Date;&quot;\""
                      + " xd:innerCtrl=\"_DTText\">"
                      + "<xsl:attribute name=\"xd:num\">"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(tns:{0},&quot;date&quot;,&quot;dateFormat:Short Date;&quot;)\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "<button class=\"xdDTButton\" xd:xctname=\"DTPicker_DTButton\""
                      + " xd:innerCtrl=\"_DTButton\" tabIndex=\"-1\">"
                      + "<img src=\"res://infopath.exe/calendar.gif\"/>"
                      + " </button>"
                      + "</div>"
                      + "</td>";
            }
            else
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      +
                      "<div style=\"WIDTH: 147px\" class=\"xdDTPicker\" title=\"\" noWrap=\"1\" xd:xctname=\"DTPicker\" xd:CtrlId=\"CTRL12\">"
                      +
                      "<span hideFocus=\"1\" class=\"xdDTText xdBehavior_FormattingNoBUI\" contentEditable=\"true\" tabIndex=\"0\" xd:xctname=\"DTPicker_DTText\""
                      + " xd:binding=\"tns:{0}\" xd:datafmt=\"&quot;datetime&quot;,&quot;dateFormat:Short Date;timeFormat:none;&quot;\" xd:boundProp=\"xd:num\" xd:innerCtrl=\"_DTText\">"
                      + "<xsl:attribute name=\"xd:num\" >"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose >"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\" >"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(tns:{0},&quot;datetime&quot;,&quot;dateFormat:Short Date;timeFormat:none;&quot;)\" />"
                      + "</xsl:when>"
                      + "<xsl:otherwise >"
                      + "<xsl:value-of select=\"tns:{0}\" />"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      +
                      "<button class=\"xdDTButton\" xd:xctname=\"DTPicker_DTButton\" xd:innerCtrl=\"_DTButton\" tabIndex=\"0\" >"
                      + "<img src=\"res://infopath.exe/calendar.gif\"/>"
                      + "</button>"
                      +
                      "</div><span hideFocus=\"1\" class=\"xdTextBox xdBehavior_Formatting\" title=\"\" contentEditable=\"true\" tabIndex=\"0\" "
                      + " xd:xctname=\"PlainText\" xd:CtrlId=\"CTRL1\" xd:binding=\"tns:{0}\" xd:datafmt=\"&quot;datetime&quot;,&quot;dateFormat:none;&quot;\" xd:boundProp=\"xd:num\" style=\"WIDTH: 144px\">"
                      + "<xsl:attribute name=\"xd:num\" >"
                      + "<xsl:value-of select=\"tns:{0}\" />"
                      + "</xsl:attribute>"
                      + "<xsl:choose >"
                      + "<xsl:when test=\"function-available('xdFormatting:formatString')\" >"
                      +
                      "<xsl:value-of select=\"xdFormatting:formatString(tns:{0},&quot;datetime&quot;,&quot;dateFormat:none;&quot;)\" />"
                      + "</xsl:when>"
                      + "<xsl:otherwise >"
                      + "<xsl:value-of select=\"tns:{0}\" />"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "</td>";
            }
            return string.Format(def, UniqueName);
        }

        #endregion

        public bool DateOnly { get; private set; }
    }

    //LookUp,
    public class LookUpFieldInfo : XFieldInfo
    {
        private readonly string _lookupListID;
        private readonly string _lookupListRelativeUrl;
        private readonly string _lookupSiteUrl;

        public LookUpFieldInfo(SPFieldLookup p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.LookUp;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");

            SPList lkpList = p_SPField.ParentList.ParentWeb.Lists[new Guid(p_SPField.LookupList)];
            LookupListName = lkpList.Title;
            LookupFieldName = p_SPField.LookupField;
            _lookupSiteUrl = p_SPField.ParentList.ParentWeb.Url;
            _lookupListID = p_SPField.LookupList;
            _lookupListRelativeUrl = lkpList.RootFolder.Url;
        }

        public string LookupListName { get; set; }

        public string LookupFieldName { get; set; }

        public string LookupUniqueName { get; set; }

        public string LookupListRelativeUrl
        {
            get { return _lookupListRelativeUrl; }
        }

        public string LookupListID
        {
            get { return _lookupListID; }
        }

        public bool AppendFieldDefXSD(XSNOperator p_XSNOperator)
        {
            bool rStatus = false;
            LookupUniqueName = string.Format("lookup{0}", p_XSNOperator.G_LkpCount);
            XSN_Lookup lookupXSD = new XSN_Lookup();
            lookupXSD.Initial(p_XSNOperator);
            lookupXSD.SavePath = lookupXSD.SavePath.Replace("lookup.xsd", string.Format("{0}.xsd", LookupUniqueName));
            lookupXSD.TemplateName = string.Format("{0}.xsd", LookupUniqueName);
            p_XSNOperator.G_XSNFiles.Add(lookupXSD);

            //Insert into myFields
            XPathNavigator _sXNav =
                lookupXSD.XPathNav.SelectSingleNode(
                    "/xsd:schema/xsd:element[@name='SharePointListItem_RW']/xsd:complexType/xsd:sequence", lookupXSD.XmlNSManager);
            if (_sXNav != null)
            {
                string refDef = string.Format("<xsd:element ref=\"d:Title\" minOccurs=\"0\" maxOccurs=\"1\" />");
                _sXNav.AppendChild(refDef);
            }
            //Insert element definition
            _sXNav = lookupXSD.XPathNav.SelectSingleNode("/xsd:schema", lookupXSD.XmlNSManager);
            if (_sXNav != null)
            {
                string elementDef =
                    string.Format(
                        "<xsd:element name=\"Title\" ma:displayName=\"Title\" type=\"xsd:string\" nillable=\"true\"  />");
                _sXNav.AppendChild(elementDef);

                lookupXSD.AppendFieldInfoMainDef(this);
                rStatus = true;
            }
            return rStatus;
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element ma:displayName=\"{1}\" name=\"{0}\" "
                                + "ma:auxDataSourceName=\"{2}\" "
                                + "ma:auxChoicesXPath=\"/dfs:myFields\" "
                                + "ma:auxValue=\"d:ID\" ma:auxDisplay=\"d:{3}\" "
                                + "nillable=\"true\" >"
                                + "<xsd:complexType>"
                                + "<xsd:simpleContent>"
                                + "<xsd:extension base=\"xsd:positiveInteger\">"

                                + "</xsd:extension>"
                                + "</xsd:simpleContent>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";
            return string.Format(elementDef, UniqueName, DisplayName, UniqueName, LookupFieldName);
        }

        //Manifest.xsf
        public override string GetManifestFileDef()
        {
            string _fileDef = "<xsf:file name=\"{0}.xsd\">"
                              + "<xsf:fileProperties>"
                              + "<xsf:property name=\"namespace\" type=\"string\""
                              + " value=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" />"
                              + "<xsf:property name=\"dataObject\" type=\"string\" value=\"{0}\"/>"
                              + "<xsf:property name=\"rootElement\" type=\"string\" value=\"myFields\"/>"
                              + "<xsf:property name=\"useOnDemandAlgorithm\" type=\"string\" value=\"yes\"/>"
                              + "</xsf:fileProperties>"
                              + "</xsf:file>";
            return string.Format(_fileDef, LookupUniqueName);
        }

        public override string GetManifestDataObjectDef()
        {
            StringBuilder dataObjectDef = new StringBuilder();
            dataObjectDef.AppendFormat("<xsf:dataObject name=\"{0}\" initOnLoad=\"yes\" schema=\"{0}.xsd\">", LookupUniqueName);
            dataObjectDef.AppendFormat("<xsf:query>");
            dataObjectDef.AppendFormat("<xsf:sharepointListAdapterRW siteURL=\"{0}/\" sharePointListID=\"{1}\"",
                _lookupSiteUrl, _lookupListID);
            dataObjectDef.AppendFormat(
                " contentTypeID=\"\" relativeListUrl=\"{0}\" queryAllowed=\"yes\" submitAllowed=\"no\" ",
                _lookupListRelativeUrl);
            dataObjectDef.AppendFormat(" name=\"{0}\" autogen=\"yes\" >", LookupUniqueName);
            dataObjectDef.AppendFormat(
                "<xsf:field internalName=\"ID\" type=\"Counter\" required=\"no\" appendOnly=\"no\" />");
            if (LookupFieldName != "ID")
            {
                dataObjectDef.AppendFormat(
                    "<xsf:field internalName=\"{0}\" type=\"Text\" required=\"no\" appendOnly=\"no\" />",
                    LookupFieldName);
            }
            dataObjectDef.AppendFormat("</xsf:sharepointListAdapterRW></xsf:query></xsf:dataObject>");

            return dataObjectDef.ToString();
        }

        //Sampledata.xml
        public override string GetSampledataDataObjectDef()
        {
            StringBuilder dataConnectionDef = new StringBuilder();
            dataConnectionDef.AppendFormat("<xd:DataConnection Name=\"{0}\" >", LookupUniqueName);
            dataConnectionDef.AppendFormat(
                "<dfs:myFields");
            dataConnectionDef.AppendFormat(
                " xmlns:pc=\"http://schemas.microsoft.com/office/infopath/2007/PartnerControls\"");
            dataConnectionDef.AppendFormat(
                " xmlns:ma=\"http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes\"");
            dataConnectionDef.AppendFormat(
                " xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"");
            dataConnectionDef.AppendFormat(" >");
            dataConnectionDef.AppendFormat("<dfs:dataFields><d:SharePointListItem_RW>");
            dataConnectionDef.AppendFormat(
                "<d:ID xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"/>");
            if (LookupFieldName != "ID")
            {
                dataConnectionDef.AppendFormat(
                    "<d:Title xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"/>");
            }
            dataConnectionDef.AppendFormat("</d:SharePointListItem_RW></dfs:dataFields>");
            dataConnectionDef.AppendFormat(
                "<xd:SchemaInfo LocalName=\"myFields\" NamespaceURI=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\">");
            dataConnectionDef.AppendFormat("<xd:RequiredAnys /></xd:SchemaInfo></dfs:myFields></xd:DataConnection>");
            dataConnectionDef.AppendFormat("<tns:{0} />", UniqueName);

            return dataConnectionDef.ToString();
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px; PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<h4><span class=\"xdlabel\">{1}</span></h4>"
                         + "</td>"
                         +
                         "<td class=\"xdTableOffsetCellComponent\" style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<select style=\"WIDTH: 100%\" class=\"xdComboBox xdBehavior_Select\""
                         + " title=\"\" size=\"1\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                         +
                         " xd:CtrlId=\"CTRL22\" xd:xctname=\"dropdown\" xd:boundProp=\"value\" value=\"\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdXDocument:GetDOM')\">"
                         + "<option/>"
                         + "<xsl:variable name=\"val\" select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         +
                         "<xsl:if test=\"not(xdXDocument:GetDOM(&quot;{2}&quot;)/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:ID=$val] or $val='')\">"
                         + "<option selected=\"selected\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</option>"
                         + "</xsl:if>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;{2}&quot;)/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW\">"
                         + "<option>"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"d:ID\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"$val=d:ID\">"
                         + "<xsl:attribute name=\"selected\">"
                         + "selected"
                         + "</xsl:attribute>"
                         + "</xsl:if>"
                         + "<xsl:value-of select=\"d:Title\"/>"
                         + "</option>"
                         + "</xsl:for-each>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<option>"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</option>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</select>"
                         + "</td>"
                         + "</tr>";
            def = string.Format(def, UniqueName, DisplayName, LookupUniqueName);
            return def;
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<select style=\"WIDTH: 100%\" class=\"xdComboBox xdBehavior_Select\""
                         + " title=\"\" size=\"1\" xd:binding=\"tns:{0}\""
                         +
                         " xd:CtrlId=\"CTRL22\" xd:xctname=\"dropdown\" xd:boundProp=\"value\" value=\"\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdXDocument:GetDOM')\">"
                         + "<option/>"
                         + "<xsl:variable name=\"val\" select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         +
                         "<xsl:if test=\"not(xdXDocument:GetDOM(&quot;{2}&quot;)/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[d:ID=$val] or $val='')\">"
                         + "<option selected=\"selected\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</option>"
                         + "</xsl:if>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;{2}&quot;)/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW\">"
                         + "<option>"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"d:ID\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"$val=d:ID\">"
                         + "<xsl:attribute name=\"selected\">"
                         + "selected"
                         + "</xsl:attribute>"
                         + "</xsl:if>"
                         + "<xsl:value-of select=\"d:Title\"/>"
                         + "</option>"
                         + "</xsl:for-each>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<option>"
                         + "<xsl:value-of select=\"tns:{0}\"/>"
                         + "</option>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</select>"
                         + "</td>";
            def = string.Format(def, UniqueName, DisplayName, LookupUniqueName);
            return def;
        }

        #endregion
    }

    //Combox,
    //Counter,
    //Boolean,
    public class BooleanFieldInfo : XFieldInfo
    {
        public BooleanFieldInfo(SPFieldBoolean p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Boolean;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"true\" >"
                          + "<xsd:complexType>"
                          + "<xsd:simpleContent>"
                          + "<xsd:extension base=\"xsd:boolean\">"

                          + "</xsd:extension>"
                          + "</xsd:simpleContent>"
                          + "</xsd:complexType>"
                          + "</xsd:element>";

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr class=\"xdTableOffsetRow\">"
                         + "<td vAlign=\"top\" class=\"xdTableOffsetCellLabel\">"
                         + "<h4><span class=\"xdlabel\">{1}</span> </h4>"
                         + "</td>"
                         + "<td vAlign=\"top\" class=\"xdTableOffsetCellComponent\">"
                         + "<div>"
                         +
                         "<input class=\"xdBehavior_Boolean\" title=\"\" type=\"checkbox\" tabIndex=\"0\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                         + " xd:CtrlId=\"CTRL4\" xd:xctname=\"CheckBox\" xd:boundProp=\"xd:value\" xd:onValue=\"true\" xd:offValue=\"false\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\" /> "
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"dfs:dataFields/tns:mainForm/tns:{0}=&quot;true&quot;\">"
                         + "<xsl:attribute name=\"CHECKED\">CHECKED</xsl:attribute>"
                         + "</xsl:if>"
                         + "</input>"
                         + "</div>"
                         + "</td>"
                         + "</tr>";
            def = string.Format(def, UniqueName, DisplayName);
            return def;
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<div>"
                         +
                         "<input class=\"xdBehavior_Boolean\" title=\"\" type=\"checkbox\" tabIndex=\"0\" xd:binding=\"tns:{0}\""
                         + " xd:CtrlId=\"CTRL42\" xd:xctname=\"CheckBox\" xd:boundProp=\"xd:value\" xd:onValue=\"true\" xd:offValue=\"false\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\"tns:{0}\" /> "
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"tns:{0}=&quot;true&quot;\">"
                         + "<xsl:attribute name=\"CHECKED\">CHECKED</xsl:attribute>"
                         + "</xsl:if>"
                         + "</input>"
                         + "</div>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //Calculated,
    //Number,
    public class NumberFieldInfo : XFieldInfo
    {
        public NumberFieldInfo(SPFieldNumber p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Number;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"true\" >"
                          + "<xsd:complexType>"
                          + "<xsd:simpleContent>"
                          + "<xsd:extension base=\"xsd:double\">"

                          + "</xsd:extension>"
                          + "</xsd:simpleContent>"
                          + "</xsd:complexType>"
                          + "</xsd:element>";

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-RIGHT: 5px\""
                         + " class=\"xdTableOffsetCellLabel\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px\""
                         + " class=\"xdTableOffsetCellComponent\">"
                         + " <span title=\"\" class=\"xdTextBox xdBehavior_Formatting\""
                         + " hideFocus=\"1\" contentEditable=\"true\" tabIndex=\"0\""
                         + " xd:xctname=\"PlainText\" xd:CtrlId=\"{0}38\""
                         + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                         + " xd:disableEditing=\"no\" xd:boundProp=\"xd:num\""
                         + " xd:datafmt=\"&quot;number&quot;,&quot;numDigits:auto;negativeOrder:1;&quot;\""
                         + " style=\"WIDTH: 100%\">"
                         + "<xsl:attribute name=\"xd:num\">"
                         + "<xsl:value-of"
                         + " select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                         + "<xsl:value-of"
                         +
                         " select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;number&quot;,&quot;numDigits:auto;negativeOrder:1;&quot;)\"/>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<xsl:value-of"
                         + " select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</span>"
                         + "</td>"
                         + "</tr>";
            def = string.Format(def, UniqueName, DisplayName);
            return def;
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + " <span class=\"xdTextBox xdBehavior_Formatting\""
                         + " hideFocus=\"1\" contentEditable=\"true\" tabIndex=\"0\""
                         + " xd:xctname=\"PlainText\" xd:CtrlId=\"{0}32\""
                         + " xd:binding=\"tns:{0}\""
                         + " xd:disableEditing=\"no\" xd:boundProp=\"xd:num\""
                         + " xd:datafmt=\"&quot;number&quot;,&quot;numDigits:auto;negativeOrder:1;&quot;\""
                         + " style=\"WIDTH: 100%\">"
                         + "<xsl:attribute name=\"xd:num\">"
                         + "<xsl:value-of"
                         + " select=\"tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                         + "<xsl:value-of"
                         +
                         " select=\"xdFormatting:formatString(tns:{0},&quot;number&quot;,&quot;numDigits:auto;negativeOrder:1;&quot;)\"/>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<xsl:value-of"
                         + " select=\"tns:{0}\"/>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</span>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //Currency,
    public class CurrencyFieldInfo : XFieldInfo
    {
        public CurrencyFieldInfo(SPFieldCurrency p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Currency;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"true\" >"
                          + "<xsd:complexType>"
                          + "<xsd:simpleContent>"
                          + "<xsd:extension base=\"xsd:decimal\">"

                          + "</xsd:extension>"
                          + "</xsd:simpleContent>"
                          + "</xsd:complexType>"
                          + "</xsd:element>";

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-RIGHT: 5px\""
                         + " class=\"xdTableOffsetCellLabel\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px\""
                         + " class=\"xdTableOffsetCellComponent\">"
                         + " <span title=\"\" class=\"xdTextBox xdBehavior_Formatting\""
                         + " hideFocus=\"1\" contentEditable=\"true\" tabIndex=\"0\""
                         + " xd:xctname=\"PlainText\" xd:CtrlId=\"{0}38\""
                         + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                         + " xd:disableEditing=\"no\" xd:boundProp=\"xd:num\""
                         +
                         " xd:datafmt=\"&quot;currency&quot;,&quot;numDigits:auto;negativeOrder:0;positiveOrder:0;currencyLocale:1033;&quot;\""
                         + " style=\"WIDTH: 100%\">"
                         + "<xsl:attribute name=\"xd:num\">"
                         + "<xsl:value-of"
                         + " select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                         + "<xsl:value-of"
                         +
                         " select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;currency&quot;,&quot;numDigits:auto;negativeOrder:0;positiveOrder:0;currencyLocale:1033;&quot;)\"/>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<xsl:value-of"
                         + " select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</span>"
                         + "</td>"
                         + "</tr>";
            def = string.Format(def, UniqueName, DisplayName);
            return def;
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + " <span class=\"xdTextBox xdBehavior_Formatting\""
                         + " hideFocus=\"1\" contentEditable=\"true\" tabIndex=\"0\""
                         + " xd:xctname=\"PlainText\" xd:CtrlId=\"{0}32\""
                         + " xd:binding=\"tns:{0}\""
                         + " xd:disableEditing=\"no\" xd:boundProp=\"xd:num\""
                         +
                         " xd:datafmt=\"&quot;currency&quot;,&quot;numDigits:auto;negativeOrder:0;positiveOrder:0;currencyLocale:1033;&quot;\""
                         + " style=\"WIDTH: 100%\">"
                         + "<xsl:attribute name=\"xd:num\">"
                         + "<xsl:value-of"
                         + " select=\"tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdFormatting:formatString')\">"
                         + "<xsl:value-of"
                         +
                         " select=\"xdFormatting:formatString(tns:{0},&quot;currency&quot;,&quot;numDigits:auto;negativeOrder:0;positiveOrder:0;currencyLocale:1033;&quot;)\"/>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<xsl:value-of"
                         + " select=\"tns:{0}\"/>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</span>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //User,
    public class UserFieldInfo : XFieldInfo
    {
        public UserFieldInfo(SPFieldUser p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.User;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"false\" >"
                                + "<xsd:complexType>"
                                + "<xsd:sequence>"
                                + "<xsd:element ref=\"pc:Person\" minOccurs=\"0\" maxOccurs=\"unbounded\" />"
                                + "</xsd:sequence>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            string _refDef = "<tns:{0} >"
                             + "<pc:Person >"
                             + "<pc:DisplayName/>"
                             + "<pc:AccountId/>"
                             + "<pc:AccountType/>"
                             + "</pc:Person>"
                             + "</tns:{0}>";

            return string.Format(_refDef, UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr style=\"MIN-HEIGHT: 47px\" class=\"xdTableOffsetRow\">"
                         +
                         "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<h4><span class=\"xdlabel\">{1}</span></h4>"
                         + "</td>"
                         +
                         "<td class=\"xdTableOffsetCellComponent\" style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span class=\"xdlabel\"></span>"
                         + "<font style=\"BACKGROUND-COLOR: #ffffff\">"
                         +
                         "<object hideFocus=\"1\" style=\"WIDTH: 447px; HEIGHT: 23px\" class=\"xdActiveX\" classid=\"clsid:61e40d31-993d-4777-8fa0-19ca59b6d0bb\" tabIndex=\"0\""
                         +
                         " tabStop=\"true\" xd:xctname=\"{{{{61e40d31-993d-4777-8fa0-19ca59b6d0bb}}}}\" xd:CtrlId=\"CTRL3\" xd:server=\"http://\""
                         +
                         " xd:bindingType=\"xmlNode\" xd:bindingProperty=\"Value\" xd:boundProp=\"xd:inline\" xd:AllowMultiple=\"false\" xd:SearchPeopleOnly=\"true\""
                         + " xd:SharePointGroup=\"0\" contentEditable=\"false\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\">"
                         + "<xsl:if test=\"function-available('xdImage:getImageUrl')\">"
                         +
                         "<xsl:attribute name=\"src\"><xsl:value-of select=\"xdImage:getImageUrl(dfs:dataFields/tns:mainForm/tns:{0})\"/></xsl:attribute>"
                         + "</xsl:if>"
                         + "<param NAME=\"ButtonFont\" VALUE=\"宋体,10,0,400,0,0,0\"/>"
                         + "<param NAME=\"ButtonText\" VALUE=\"\"/>"
                         + "<param NAME=\"DisplayNameXPath\" VALUE=\"pc:DisplayName\"/>"
                         + "<param NAME=\"ObjectIdXPath\" VALUE=\"pc:AccountId\"/>"
                         + "<param NAME=\"ObjectTypeXPath\" VALUE=\"pc:AccountType\"/>"
                         + "<param NAME=\"SiteUrlXPath\" VALUE=\"/Context/@siteUrl\"/>"
                         + "<param NAME=\"SiteUrlDataSource\" VALUE=\"Context\"/>"
                         +
                         "<param NAME=\"NewNodeTemplate\" VALUE=\"&lt;pc:Person xmlns:pc=&quot;http://schemas.microsoft.com/office/infopath/2007/PartnerControls&quot;&gt;&#xA;"
                         +
                         "	&lt;pc:DisplayName&gt;&lt;/pc:DisplayName&gt;&#xA;	&lt;pc:AccountId&gt;&lt;/pc:AccountId&gt;&#xA;	&lt;pc:AccountType&gt;&lt;/pc:AccountType&gt;&#xA;&lt;/pc:Person&gt;\"/>"
                         + "<param NAME=\"BackgroundColor\" VALUE=\"2147483653\"/>"
                         + "<param NAME=\"MaxLines\" VALUE=\"4\"/>"
                         + "<param NAME=\"Direction\" VALUE=\"0\"/>"
                         + "</object>"
                         + "</font>"
                         + "</td>"
                         + "</tr>";
            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span class=\"xdlabel\"></span>"
                         + "<font style=\"BACKGROUND-COLOR: #ffffff\">"
                         +
                         "<object hideFocus=\"1\" style=\"WIDTH: 447px; HEIGHT: 23px\" class=\"xdActiveX\" classid=\"clsid:61e40d31-993d-4777-8fa0-19ca59b6d0bb\" tabIndex=\"0\""
                         +
                         " tabStop=\"true\" xd:xctname=\"{{{{61e40d31-993d-4777-8fa0-19ca59b6d0bb}}}}\" xd:CtrlId=\"CTRL32\" xd:server=\"http://\""
                         +
                         " xd:bindingType=\"xmlNode\" xd:bindingProperty=\"Value\" xd:boundProp=\"xd:inline\" xd:AllowMultiple=\"false\" xd:SearchPeopleOnly=\"true\""
                         + " xd:SharePointGroup=\"0\" contentEditable=\"false\" xd:binding=\"tns:{0}\">"
                         + "<xsl:if test=\"function-available('xdImage:getImageUrl')\">"
                         +
                         "<xsl:attribute name=\"src\"><xsl:value-of select=\"xdImage:getImageUrl(tns:{0})\"/></xsl:attribute>"
                         + "</xsl:if>"
                         + "<param NAME=\"ButtonFont\" VALUE=\"宋体,10,0,400,0,0,0\"/>"
                         + "<param NAME=\"ButtonText\" VALUE=\"\"/>"
                         + "<param NAME=\"DisplayNameXPath\" VALUE=\"pc:DisplayName\"/>"
                         + "<param NAME=\"ObjectIdXPath\" VALUE=\"pc:AccountId\"/>"
                         + "<param NAME=\"ObjectTypeXPath\" VALUE=\"pc:AccountType\"/>"
                         + "<param NAME=\"SiteUrlXPath\" VALUE=\"/Context/@siteUrl\"/>"
                         + "<param NAME=\"SiteUrlDataSource\" VALUE=\"Context\"/>"
                         +
                         "<param NAME=\"NewNodeTemplate\" VALUE=\"&lt;pc:Person xmlns:pc=&quot;http://schemas.microsoft.com/office/infopath/2007/PartnerControls&quot;&gt;&#xA;"
                         +
                         "	&lt;pc:DisplayName&gt;&lt;/pc:DisplayName&gt;&#xA;	&lt;pc:AccountId&gt;&lt;/pc:AccountId&gt;&#xA;	&lt;pc:AccountType&gt;&lt;/pc:AccountType&gt;&#xA;&lt;/pc:Person&gt;\"/>"
                         + "<param NAME=\"BackgroundColor\" VALUE=\"2147483653\"/>"
                         + "<param NAME=\"MaxLines\" VALUE=\"4\"/>"
                         + "<param NAME=\"Direction\" VALUE=\"0\"/>"
                         + "</object>"
                         + "</font>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //Note,
    public class NoteFieldInfo : XFieldInfo
    {
        public bool richText;
        public NoteFieldInfo(SPFieldMultiLineText p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Note;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
            richText = p_SPField.RichText;
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = string.Empty;
            if (richText)
            {
                elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" ma:allowDeletion=\"false\" >"
                                + "<xsd:complexType mixed=\"true\">"
                                + "<xsd:sequence>"
                                +
                                "<xsd:any minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"lax\" namespace=\"http://www.w3.org/1999/xhtml\"/>"
                                + "</xsd:sequence>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";
            }
            else
            {
                elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\"  ma:formatSpec=\"plainMultiline\" ma:formatCategory=\"string\" nillable=\"true\" type=\"xsd:string\" />";
            }

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Manifest.xsf
        public override string GetManifestXmlToEditDef()
        {
            string xmlToEditDef = string.Empty;
            if (richText)
            {
                xmlToEditDef =
                "<xsf:xmlToEdit name=\"{0}_x1\" item=\"/dfs:myFields/dfs:dataFields/tns:mainForm/tns:{0}\">"
                                   + "<xsf:editWith type=\"rich\" autoComplete=\"no\" component=\"xField\">"
                                   + "</xsf:editWith>"
                                   + "</xsf:xmlToEdit>";
            }
            else
            {
                xmlToEditDef =
                "<xsf:xmlToEdit name=\"{0}_x1\" item=\"/dfs:myFields/dfs:dataFields/tns:mainForm/tns:{0}\">"
                                   + "<xsf:editWith type=\"plainMultiline\" component=\"xField\">"
                                   + "</xsf:editWith>"
                                   + "</xsf:xmlToEdit>";
            }

            return string.Format(xmlToEditDef, UniqueName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = string.Empty;
            if (richText)
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-RIGHT: 5px\""
                         + " class=\"xdTableOffsetCellLabel\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         + "<td vAlign=\"top\" class=\"xdTableOffsetCellComponent\""
                         +
                         "  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span hideFocus=\"1\" class=\"xdRichTextBox\" title=\"\" xd:xctname=\"RichText\""
                         + " xd:CtrlId=\"CTRL2\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" tabIndex=\"0\""
                         + " style=\"WIDTH: 100%; HEIGHT: 50px\">"
                         + "<xsl:copy-of select=\"dfs:dataFields/tns:mainForm/tns:{0}/node()\"/>"
                         + "</span>"
                         + "</td>"
                         + "</tr>";
            }
            else
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td style=\"VERTICAL-ALIGN: top; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; PADDING-RIGHT: 5px\""
                         + " class=\"xdTableOffsetCellLabel\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         + "<td vAlign=\"top\" class=\"xdTableOffsetCellComponent\""
                         +
                         "  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span hideFocus=\"1\" class=\"xdTextBox\" title=\"\" xd:xctname=\"PlainText\""
                         + " xd:CtrlId=\"CTRL2\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" tabIndex=\"0\""
                         + " xd:datafmt=\"&quot;string&quot;,&quot;plainMultiline&quot;\""
                         + " style=\"OVERFLOW-X: auto; OVERFLOW-Y: auto; WIDTH: 100%; WORD-WRAP: break-word; WHITE-SPACE: normal; HEIGHT: 50px\">"
                         + "<xsl:choose xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
                         + "<xsl:when"
                         + " test=\"function-available('xdFormatting:formatString')\">"
                         + "<xsl:value-of"
                         + " select=\"xdFormatting:formatString(dfs:dataFields/tns:mainForm/tns:{0},&quot;string&quot;,&quot;plainMultiline&quot;)\""
                         + " disable-output-escaping=\"yes\"/>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<xsl:value-of"
                         + " select=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                         + " disable-output-escaping=\"yes\"/>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</span>"
                         + "</td>"
                         + "</tr>";
            }

            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def = string.Empty;
            if (richText)
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<span hideFocus=\"1\" class=\"xdRichTextBox\" title=\"\" xd:xctname=\"RichText\""
                      + " xd:CtrlId=\"CTRL22\" xd:binding=\"tns:{0}\" tabIndex=\"0\""
                      + " style=\"WIDTH: 100%; HEIGHT: 50px\">"
                      + "<xsl:copy-of select=\"tns:{0}/node()\"/>"
                      + "</span>"
                      + "</td>";
            }
            else
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<span hideFocus=\"1\" class=\"xdTextBox\" title=\"\" xd:xctname=\"PlainText\""
                      + " xd:CtrlId=\"CTRL22\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" tabIndex=\"0\""
                         + " xd:datafmt=\"&quot;string&quot;,&quot;plainMultiline&quot;\""
                      + " style=\"OVERFLOW-X: auto; OVERFLOW-Y: auto; WIDTH: 100%; WORD-WRAP: break-word; WHITE-SPACE: normal; HEIGHT: 50px\">"
                      + "<xsl:copy-of select=\"dfs:dataFields/tns:mainForm/tns:{0}/node()\"/>"
                      + "</span>"
                      + "</td>";
            }
            return string.Format(def, UniqueName);
        }

        #endregion
    }

    //Dropdown,RadioButtons,
    public class DropdownFieldInfo : XFieldInfo
    {
        public DropdownFieldInfo(SPFieldChoice p_SPField, string p_CTypeName)
        {
            ChoiceList = new List<string>();
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Dropdown;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
            foreach (string choiceItem in p_SPField.Choices)
            {
                ChoiceList.Add(choiceItem);
            }
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{1}\" ma:displayName=\"{2}\" ma:readOnly=\"false\" ma:allowDeletion=\"true\" ma:auxDataSourceName=\"{0}\""
                                +
                                " ma:auxChoicesXPath=\"/root/{1}/SharePointListChoice_RW\" ma:auxValue=\".\" ma:auxDisplay=\"@DisplayName\" >"
                                + "<xsd:complexType>"
                                + "<xsd:simpleContent>"
                                + "<xsd:extension base=\"xsd:string\">"

                                + "</xsd:extension>"
                                + "</xsd:simpleContent>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";

            return string.Format(elementDef, "OptionDataSourceConnection", UniqueName, DisplayName);
        }

        //Sampledata.xml
        public override string GetSampledataOptionDSElementDef()
        {
            return string.Format("<{0}><SharePointListChoice_RW/></{0}>", UniqueName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr style=\"MIN-HEIGHT: 31px\" class=\"xdTableOffsetRow\">"
                         +
                         "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\"></span>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         +
                         "<td class=\"xdTableOffsetCellComponent\" style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span class=\"xdlabel\"></span>"
                         + "<font style=\"BACKGROUND-COLOR: #ffffff\">"
                         +
                         "<select style=\"WIDTH: 100%\" class=\"xdComboBox xdBehavior_Select\" title=\"\" size=\"1\" xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" xd:CtrlId=\"{0}\" xd:xctname=\"dropdown\" xd:boundProp=\"value\" value=\"\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdXDocument:GetDOM')\">"
                         + "<option/>"
                         + "<xsl:variable name=\"val\" select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         +
                         "<xsl:if test=\"not(xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW[.=$val] or $val='')\">"
                         + "<option selected=\"selected\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</option>"
                         + "</xsl:if>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW\">"
                         + "<option>"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"$val=.\">"
                         + "<xsl:attribute name=\"selected\">selected</xsl:attribute>"
                         + "</xsl:if>"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</option>"
                         + "</xsl:for-each>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<option>"
                         + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                         + "</option>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</select>"
                         + "</font>"
                         + "</td>"
                         + "</tr>";
            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<span class=\"xdlabel\"></span>"
                         + "<font style=\"BACKGROUND-COLOR: #ffffff\">"
                         +
                         "<select style=\"WIDTH: 100%\" class=\"xdComboBox xdBehavior_Select\" title=\"\" size=\"1\" "
                         + " xd:binding=\"tns:{0}\" xd:CtrlId=\"{0}2\" xd:xctname=\"dropdown\" xd:boundProp=\"value\" value=\"\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"tns:{0}\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:choose>"
                         + "<xsl:when test=\"function-available('xdXDocument:GetDOM')\">"
                         + "<option/>"
                         + "<xsl:variable name=\"val\" select=\"tns:{0}\"/>"
                         +
                         "<xsl:if test=\"not(xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW[.=$val] or $val='')\">"
                         + "<option selected=\"selected\">"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:value-of select=\"$val\"/>"
                         + "</option>"
                         + "</xsl:if>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW\">"
                         + "<option>"
                         + "<xsl:attribute name=\"value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\"$val=.\">"
                         + "<xsl:attribute name=\"selected\">selected</xsl:attribute>"
                         + "</xsl:if>"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</option>"
                         + "</xsl:for-each>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         + "<option>"
                         + "<xsl:value-of select=\"tns:{0}\"/>"
                         + "</option>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</select>"
                         + "</font>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        //Choice.xml
        public override string GetChoiceXMLElementDef()
        {
            StringBuilder elementDef = new StringBuilder();
            elementDef.AppendFormat("<{0}>", UniqueName);
            foreach (string choiceItem in ChoiceList)
            {
                elementDef.AppendFormat("<SharePointListChoice_RW DisplayName=\"{0}\">{0}</SharePointListChoice_RW>",
                    choiceItem);
            }
            elementDef.AppendFormat("</{0}>", UniqueName);

            return elementDef.ToString();
        }

        //Choice.xsd
        public override string GetChoiceXSDElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\">"
                                + "<xsd:complexType>"
                                + "<xsd:sequence>"
                                +
                                "<xsd:element ref=\"SharePointListChoice_RW\" minOccurs=\"0\" maxOccurs=\"unbounded\"></xsd:element>"
                                + "</xsd:sequence>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";

            return string.Format(elementDef, UniqueName);
        }

        #endregion

        public List<string> ChoiceList { get; set; }
    }

    //MultiChoice,
    public class MultiChoiceFieldInfo : XFieldInfo
    {
        public MultiChoiceFieldInfo(SPFieldMultiChoice p_SPField, string p_CTypeName)
        {
            ChoiceList = new List<string>();
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.MultiChoice;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");
            foreach (string choiceItem in p_SPField.Choices)
            {
                ChoiceList.Add(choiceItem);
            }
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"false\">"
                                + "<xsd:complexType>"
                                + "<xsd:sequence>"
                                + "<xsd:element ref=\"tns:{0}_1\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>"
                                + "</xsd:sequence>"

                                + "</xsd:complexType>"
                                + "</xsd:element>"
                                + "<xsd:element nillable=\"false\" name=\"{0}_1\" type=\"xsd:string\"/>";

            elementDef = string.Format(elementDef, UniqueName, DisplayName);
            return elementDef;
        }

        //Manifest.xsf
        public override string GetManifestXmlToEditDef()
        {
            string xmlToEditDef = "<xsf:xmlToEdit name=\"{0}_x1\" item=\"/dfs:myFields/dfs:dataFields/tns:mainForm/tns:{0}/tns:{0}_1\">"
                                  + "<xsf:editWith autoComplete=\"no\" component=\"xTextList\">"
                                  + "</xsf:editWith>"
                                  + "</xsf:xmlToEdit>";
            xmlToEditDef = string.Format(xmlToEditDef, UniqueName);
            return xmlToEditDef;
        }

        //Sampledata.xml
        public override string GetSampledataOptionDSElementDef()
        {
            return string.Format("<{0}><SharePointListChoice_RW/></{0}>", UniqueName);
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} ><tns:{0}_1></tns:{0}_1></tns:{0}>", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def = "<tr class=\"xdTableOffsetRow\">"
                         +
                         "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<h4>"
                         + "<span class=\"xdlabel\">{1}</span>"
                         + "</h4>"
                         + "</td>"
                         +
                         "<td class=\"xdTableOffsetCellComponent\" style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<xsl:choose>"
                         +
                         "<xsl:when test=\"function-available('ipApp:GetMajorVersion') and ipApp:GetMajorVersion() &gt;= 12\">"
                         +
                         "<span style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px\"  class=\"xdMultiSelectList\" title=\"\" xd:CtrlId=\"{0}\" xd:xctname=\"multiselectlistbox\""
                         + " xd:boundProp=\"value\" tabIndex=\"-1\" xd:ref=\"dfs:dataFields/tns:mainForm/tns:{0}/tns:{0}_1\">"
                         + "<xsl:variable name=\"values\"  select=\"dfs:dataFields/tns:mainForm/tns:{0}/tns:{0}_1\"/>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW\">"
                         + "<span class=\"xdMultiSelectListItem\">"
                         +
                         "<input type=\"checkbox\" xd:boundProp=\"xd:value\" xd:binding=\".\" xd:xctname=\"CheckBox\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"xd:onValue\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"title\">"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\".=$values\">"
                         + "<xsl:attribute name=\"CHECKED\">"
                         + "CHECKED"
                         + "</xsl:attribute>"
                         + "</xsl:if>"
                         + "</input>"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</span>"
                         + "</xsl:for-each>"
                         +
                         "<xsl:variable name=\"options\"  select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW/.\"/>"
                         + "<xsl:for-each select=\"dfs:dataFields/tns:mainForm/tns:{0}/tns:{0}_1[not(.=$options)]\">"
                         + "<xsl:if test=\"normalize-space(.)!=''\">"
                         + "<span class=\"xdMultiSelectListItem\">"
                         +
                         "<input type=\"checkbox\" CHECKED=\"CHECKED\" xd:onValue=\"{{.}}\" xd:boundProp=\"xd:value\" xd:binding=\".\"  xd:xctname=\"CheckBox\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"title\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "</input>"
                         + "<xsl:value-of select=\".\"/>"
                         + "</span>"
                         + "</xsl:if>"
                         + "</xsl:for-each>"
                         + "</span>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         +
                         "<span class=\"xdRepeating\" xd:xctname=\"BulletedList\" title=\"\" xd:CtrlId=\"{0}\" xd:boundProp=\"value\" style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px; HEIGHT: auto;\">"
                         + "<ol style=\"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LIST-STYLE-TYPE: disc\">"
                         + "<xsl:for-each select=\"dfs:dataFields/tns:mainForm/tns:{0}/tns:{0}_1\">"
                         + "<li>"
                         +
                         "<span class=\"xdListItem\" hideFocus=\"1\" contentEditable=\"true\" xd:CtrlId=\"{0}\" xd:xctname=\"ListItem_Plain\""
                         +
                         " xd:binding=\".\" style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px; HEIGHT:auto; WIDTH: 100%; WHITE-SPACE: normal; WORD-WRAP: break-word;\" tabIndex=\"0\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</span>"
                         + "</li>"
                         + "</xsl:for-each>"
                         + "</ol>"
                         + "</span>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</td>"
                         + "</tr>";
            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                         + "<xsl:choose>"
                         +
                         "<xsl:when test=\"function-available('ipApp:GetMajorVersion') and ipApp:GetMajorVersion() &gt;= 12\">"
                         +
                         "<span style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px\"  class=\"xdMultiSelectList\" title=\"\" xd:CtrlId=\"{0}\" xd:xctname=\"multiselectlistbox\""
                         + " xd:boundProp=\"value\" tabIndex=\"-1\" xd:ref=\"tns:{0}/tns:{0}_1\">"
                         + "<xsl:variable name=\"values\"  select=\"tns:{0}/tns:{0}_1\"/>"
                         +
                         "<xsl:for-each select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW\">"
                         + "<span class=\"xdMultiSelectListItem\">"
                         +
                         "<input type=\"checkbox\" xd:boundProp=\"xd:value\" xd:binding=\".\" xd:xctname=\"CheckBox\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"xd:onValue\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"title\">"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:if test=\".=$values\">"
                         + "<xsl:attribute name=\"CHECKED\">"
                         + "CHECKED"
                         + "</xsl:attribute>"
                         + "</xsl:if>"
                         + "</input>"
                         + "<xsl:value-of select=\"@DisplayName\"/>"
                         + "</span>"
                         + "</xsl:for-each>"
                         +
                         "<xsl:variable name=\"options\"  select=\"xdXDocument:GetDOM(&quot;OptionDataSourceConnection&quot;)/root/{0}/SharePointListChoice_RW/.\"/>"
                         + "<xsl:for-each select=\"tns:{0}_1[not(.=$options)]\">"
                         + "<xsl:if test=\"normalize-space(.)!=''\">"
                         + "<span class=\"xdMultiSelectListItem\">"
                         +
                         "<input type=\"checkbox\" CHECKED=\"CHECKED\" xd:onValue=\"{{{{.}}}}\" xd:boundProp=\"xd:value\" xd:binding=\".\"  xd:xctname=\"CheckBox\" tabIndex=\"0\">"
                         + "<xsl:attribute name=\"xd:value\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "<xsl:attribute name=\"title\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</xsl:attribute>"
                         + "</input>"
                         + "<xsl:value-of select=\".\"/>"
                         + "</span>"
                         + "</xsl:if>"
                         + "</xsl:for-each>"
                         + "</span>"
                         + "</xsl:when>"
                         + "<xsl:otherwise>"
                         +
                         "<span class=\"xdRepeating\" xd:xctname=\"BulletedList\" title=\"\" xd:CtrlId=\"{0}\" xd:boundProp=\"value\" style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px; HEIGHT: auto;\">"
                         + "<ol style=\"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LIST-STYLE-TYPE: disc\">"
                         + "<xsl:for-each select=\"tns:{0}/tns:{0}_1\">"
                         + "<li>"
                         +
                         "<span class=\"xdListItem\" hideFocus=\"1\" contentEditable=\"true\" xd:CtrlId=\"{0}\" xd:xctname=\"ListItem_Plain\""
                         +
                         " xd:binding=\".\" style=\"TEXT-ALIGN: left; WIDTH: 100%; HEIGHT: 100px; HEIGHT:auto; WIDTH: 100%; WHITE-SPACE: normal; WORD-WRAP: break-word;\" tabIndex=\"0\">"
                         + "<xsl:value-of select=\".\"/>"
                         + "</span>"
                         + "</li>"
                         + "</xsl:for-each>"
                         + "</ol>"
                         + "</span>"
                         + "</xsl:otherwise>"
                         + "</xsl:choose>"
                         + "</td>";
            return string.Format(def, UniqueName);
        }

        //Choice.xml
        public override string GetChoiceXMLElementDef()
        {
            StringBuilder elementDef = new StringBuilder();
            elementDef.AppendFormat("<{0}>", UniqueName);
            foreach (string choiceItem in ChoiceList)
            {
                elementDef.AppendFormat("<SharePointListChoice_RW DisplayName=\"{0}\">{0}</SharePointListChoice_RW>",
                    choiceItem);
            }
            elementDef.AppendFormat("</{0}>", UniqueName);

            return elementDef.ToString();
        }

        //Choice.xsd
        public override string GetChoiceXSDElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\">"
                                + "<xsd:complexType>"
                                + "<xsd:sequence>"
                                +
                                "<xsd:element ref=\"SharePointListChoice_RW\" minOccurs=\"0\" maxOccurs=\"unbounded\"></xsd:element>"
                                + "</xsd:sequence>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";

            return string.Format(elementDef, UniqueName);
        }

        #endregion

        public List<string> ChoiceList { get; set; }
    }

    //Url,Picture
    public class UrlFieldInfo : XFieldInfo
    {
        public UrlFieldInfo(SPFieldUrl p_SPField, string p_CTypeName)
        {
            InternalName = p_SPField.InternalName;
            DisplayName = p_SPField.Title;
            FieldInfoType = FieldInfoType.Url;
            ReadOnly = p_SPField.ReadOnlyField;
            Hidden = p_SPField.Hidden;
            DefaultValue = p_SPField.DefaultValue;
            UniqueName =
                string.Format("{0}_{1}_{2}", p_SPField.ParentList.Title, p_CTypeName, p_SPField.InternalName).Replace(" ", "_");

            UrlType = p_SPField.DisplayFormat.Equals(SPUrlFieldFormatType.Hyperlink);
        }

        #region Field Definition for XSN

        //Myschema.xsd
        public override string GetMyschemaElementDef()
        {
            string elementDef = "<xsd:element name=\"{0}\" ma:displayName=\"{1}\" nillable=\"false\" >"
                                + "<xsd:complexType>"
                                + "<xsd:simpleContent>"
                                + "<xsd:extension base=\"xsd:anyURI\">"
                                + "<xsd:attribute name=\"Description\" type=\"xsd:string\"/>"
                                + "</xsd:extension>"
                                + "</xsd:simpleContent>"
                                + "</xsd:complexType>"
                                + "</xsd:element>";

            return string.Format(elementDef, UniqueName, DisplayName);
        }

        //Manifest.xsf
        public override string GetManifestXmlToEditDef()
        {
            string xmlToEditDef = "<xsf:xmlToEdit name=\"{0}_x1\" item=\"/dfs:myFields/dfs:dataFields/tns:mainForm/tns:{0}\">"
                                  + "<xsf:editWith component=\"xImage\">"
                                  + "</xsf:editWith>"
                                  + "</xsf:xmlToEdit>";
            xmlToEditDef = string.Format(xmlToEditDef, UniqueName);
            return xmlToEditDef;
        }

        //Template.xml
        public override string GetTemplateElementDef()
        {
            return string.Format("<tns:{0} Description=\"\" />", UniqueName);
        }

        //View.xsl
        public override string GetViewElementDef()
        {
            string def;
            if (UrlType)
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                      +
                      "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<h4>"
                      + "<span class=\"xdlabel\">{1}</span>"
                      + "</h4>"
                      + "</td>"
                      + "<td class=\"xdTableOffsetCellComponent\" "
                      +
                      "style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px; PADDING-RIGHT: 22px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<span class=\"xdHyperlinkBox xdBehavior_Formatting xdHyperlinkBoxClickable\" "
                      + "tabIndex=\"-1\" "
                      + "xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\" "
                      + "xd:CtrlId=\"CTRL18\" xd:xctname=\"HyperlinkBox\" "
                      + "xd:boundProp=\"href\" xd:boundPropSecondary=\"displaytext\" "
                      + "xd:binding_secondary=\"dfs:dataFields/tns:mainForm/tns:{0}/@Description\" "
                      + "style=\"WIDTH: 100%; FONT-FAMILY: Tahoma; FONT-SIZE: 8pt\">"
                      + "<button class=\"xdHyperlinkBoxButtonClickable\" tabIndex=\"0\">"
                      + "<img style=\"vertical-align:bottom\" src=\"res://infopath.exe/hyperlinkbox.png\"/>"
                      + "</button>"
                      + "<span style=\"width:5px;\"/>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(dfs:dataFields/tns:mainForm/tns:{0})!=0\">"
                      + "<A class=\"hyperlinkAnchor\" tabIndex=\"0\" style=\"\">"
                      + "<xsl:attribute name=\"title\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute name=\"href\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(dfs:dataFields/tns:mainForm/tns:{0}/@Description)=0\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}/@Description\"/>"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</A>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>Click here to insert a hyperlink"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "</td>"
                      + "</tr>";
            }
            else
            {
                def = "<tr class=\"xdTableOffsetRow\">"
                      +
                      "<td class=\"xdTableOffsetCellLabel\" style=\"PADDING-BOTTOM: 4px;  PADDING-RIGHT: 5px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<h4>"
                      + "<span class=\"xdlabel\">{1}</span>"
                      + "</h4>"
                      + "</td>"
                      +
                      "<td style=\"PADDING-RIGHT: 22px; PADDING-LEFT: 5px; PADDING-BOTTOM: 4px; VERTICAL-ALIGN: top; PADDING-TOP: 4px\""
                      + " class=\"xdTableOffsetCellComponent\">"
                      + "<div>"
                      + "<img class=\"xdLinkedPicture\" hideFocus=\"1\" tabIndex=\"0\""
                      + " xd:xctname=\"LinkedImage\" xd:CtrlId=\"CTRL18\""
                      + " xd:binding=\"dfs:dataFields/tns:mainForm/tns:{0}\""
                      + " xd:boundProp=\"src\" tabStop=\"true\""
                      + " xd:boundPropSecondary=\"displaytext\""
                      + " xd:binding_secondary=\"dfs:dataFields/tns:mainForm/tns:{0}\">"
                      + "<xsl:attribute  name=\"src\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute  name=\"displaytext\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}/@Description\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute  name=\"alt\">"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(dfs:dataFields/tns:mainForm/tns:{0}) &gt; 0\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}/@Description\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>Click here to insert a picture"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</xsl:attribute>"
                      + "</img>"
                      + "</div>"
                      + "</td>"
                      + "</tr>";
            }
            return string.Format(def, UniqueName, DisplayName);
        }

        public override string GetViewSubElementDef()
        {
            string def;
            if (UrlType)
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<span class=\"xdHyperlinkBox xdBehavior_Formatting xdHyperlinkBoxClickable\" "
                      + "tabIndex=\"-1\" "
                      + "xd:binding=\"tns:{0}\" "
                      + "xd:CtrlId=\"CTRL18\" xd:xctname=\"HyperlinkBox\" "
                      + "xd:boundProp=\"href\" xd:boundPropSecondary=\"displaytext\" "
                      + "xd:binding_secondary=\"tns:{0}/@Description\" "
                      + "style=\"WIDTH: 100%; FONT-FAMILY: Tahoma; FONT-SIZE: 8pt\">"
                      + "<button class=\"xdHyperlinkBoxButtonClickable\" tabIndex=\"0\">"
                      + "<img style=\"vertical-align:bottom\" src=\"res://infopath.exe/hyperlinkbox.png\"/>"
                      + "</button>"
                      + "<span style=\"width:5px;\"/>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(tns:{0})!=0\">"
                      + "<A class=\"hyperlinkAnchor\" tabIndex=\"0\" style=\"\">"
                      + "<xsl:attribute name=\"title\">"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute name=\"href\">"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(tns:{0}/@Description)=0\">"
                      + "<xsl:value-of select=\"dfs:dataFields/tns:mainForm/tns:{0}\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>"
                      + "<xsl:value-of select=\"tns:{0}/@Description\"/>"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</A>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>Click here to insert a hyperlink"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</span>"
                      + "</td>";
            }
            else
            {
                def = "<td  style=\"PADDING-BOTTOM: 4px; PADDING-LEFT: 5px;  VERTICAL-ALIGN: top; PADDING-TOP: 4px\">"
                      + "<div>"
                      + "<img class=\"xdLinkedPicture\" hideFocus=\"1\" tabIndex=\"0\""
                      + " "
                      + " xd:xctname=\"LinkedImage\" xd:CtrlId=\"CTRL18\""
                      + " xd:binding=\"tns:{0}\""
                      + " xd:boundProp=\"src\" tabStop=\"true\""
                      + " xd:boundPropSecondary=\"displaytext\""
                      + " xd:binding_secondary=\"tns:{0}\">"
                      + "<xsl:attribute  name=\"src\">"
                      + "<xsl:value-of select=\"tns:{0}\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute  name=\"displaytext\">"
                      + "<xsl:value-of select=\"tns:{0}/@Description\"/>"
                      + "</xsl:attribute>"
                      + "<xsl:attribute  name=\"alt\">"
                      + "<xsl:choose>"
                      + "<xsl:when test=\"string-length(tns:{0}) &gt; 0\">"
                      + "<xsl:value-of select=\"tns:{0}/@Description\"/>"
                      + "</xsl:when>"
                      + "<xsl:otherwise>Click here to insert a picture"
                      + "</xsl:otherwise>"
                      + "</xsl:choose>"
                      + "</xsl:attribute>"
                      + "</img>"
                      + "</div>"
                      + "</td>";
            }
            return string.Format(def, UniqueName);
        }

        #endregion

        public bool UrlType { get; set; }
    }

    #endregion

    public class FieldInfoFactory
    {
        public static XFieldInfo GetFieldInfoDefinition(SPField p_SField, string p_CTypeName)
        {
            switch (p_SField.Type)
            {
                case SPFieldType.Boolean:
                    return new BooleanFieldInfo((SPFieldBoolean)p_SField, p_CTypeName);
                case SPFieldType.Calculated:
                    break;
                case SPFieldType.Choice:
                    return new DropdownFieldInfo((SPFieldChoice)p_SField, p_CTypeName);
                case SPFieldType.Currency:
                    return new CurrencyFieldInfo((SPFieldCurrency)p_SField, p_CTypeName);
                case SPFieldType.DateTime:
                    return new DateTimeFieldInfo((SPFieldDateTime)p_SField, p_CTypeName);
                case SPFieldType.Lookup:
                    return new LookUpFieldInfo((SPFieldLookup)p_SField, p_CTypeName);
                case SPFieldType.MultiChoice:
                    return new MultiChoiceFieldInfo((SPFieldMultiChoice)p_SField, p_CTypeName);
                case SPFieldType.Note:
                    return new NoteFieldInfo((SPFieldMultiLineText)p_SField, p_CTypeName);
                case SPFieldType.Number:
                    return new NumberFieldInfo((SPFieldNumber)p_SField, p_CTypeName);
                case SPFieldType.Text:
                    return new TextFieldInfo((SPFieldText)p_SField, p_CTypeName);
                case SPFieldType.URL:
                    return new UrlFieldInfo((SPFieldUrl)p_SField, p_CTypeName);
                case SPFieldType.User:
                    return new UserFieldInfo((SPFieldUser)p_SField, p_CTypeName);
            }

            return null;
        }
    }
}